package com.winchain.chainbill.bill.biz.send.service.impl;

import com.shell.bee.acct.account.po.AcctBas;
import com.shell.bee.base.utils.DateUtil;
import com.shell.bee.base.utils.SystemUtil;
import com.winchain.chainbill.basic.cus.po.CusRec;
import com.winchain.chainbill.basic.cus.service.CusRecService;
import com.winchain.chainbill.bill.base.po.CbHldr;
import com.winchain.chainbill.bill.base.po.CbRec;
import com.winchain.chainbill.bill.base.service.CbHldrService;
import com.winchain.chainbill.bill.biz.send.service.BillHoldService;
import com.winchain.chainbill.trade.service.BillAcctService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("billHoldService")
public class BillHoldServiceImpl implements BillHoldService {
	@Autowired
	private CusRecService basCusService;
	@Autowired
	private BillAcctService billAcctService;
	@Autowired
	private CbHldrService cbHldrService;

	public void own(CbRec bill, String ownerId) {
		int level = bill.getHldrLvl().intValue();
		bill.setHldrLvl(Integer.valueOf(++level));

		CbHldr owner = new CbHldr();
		owner.setHoldId(SystemUtil.getUUID());
		owner.setBillId(bill.getBillId());
		owner.setHldrId(ownerId);
		CusRec cus = (CusRec) this.basCusService.selectByKey(ownerId);
		owner.setHldrNm(cus.getCusName());
		AcctBas acct = new AcctBas();

		acct = this.billAcctService.getAcctBas(ownerId, null, "00");
		owner.setHldrAcct(acct.getAcctNo());
		owner.setRcvDate(DateUtil.getSystemDate());
		owner.setHldrLvl(Integer.valueOf(level));

		this.cbHldrService.save(owner);
	}
}
